/**
 * 
 */
package ufpr.mestrado.ais.base.operator.selection;

import java.util.Comparator;

import jmetal.base.SolutionSet;
import jmetal.base.operator.selection.Selection;

/**
 * @author gabriel
 * 
 */
public class optAINetBestSolutionSelection extends Selection {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6246675593317103241L;

	// Comparator
	private Comparator comparator_;

	/**
	 * 
	 */
	public optAINetBestSolutionSelection(Comparator comparator) {
		comparator_ = comparator;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see jmetal.base.Operator#execute(java.lang.Object)
	 */
	@Override
	public Object execute(Object object) {
		SolutionSet solutionSet = (SolutionSet) object;

		if (solutionSet.size() == 0) {
			return null;
		}
		int bestSolution;

		bestSolution = 0;

		for (int i = 1; i < solutionSet.size(); i++) {
			if (comparator_.compare(solutionSet.get(i),
					solutionSet.get(bestSolution)) > 0)
				bestSolution = i;
		} // for

		return bestSolution;
	}

}
